package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.domain.ProductDept;
import com.ruoyi.zhgd.dto.CollectProductDto;
import com.ruoyi.zhgd.dto.NSysStationDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.CollectProductVo;
import com.ruoyi.zhgd.domain.bo.CollectProductBo;
import com.ruoyi.zhgd.service.ICollectProductService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 派车信息
 *
 * @author yhy
 * @date 2023-09-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/product")
public class CollectProductController extends BaseController {

    private final ICollectProductService iCollectProductService;

    /**
     * 查询派车信息列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<CollectProductVo> list(CollectProductBo bo, PageQuery pageQuery) {
        return iCollectProductService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出派车信息列表
     */
    @SaCheckLogin
    @Log(title = "派车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CollectProductBo bo, HttpServletResponse response) {
        List<CollectProductVo> list = iCollectProductService.queryList(bo);
        ExcelUtil.exportExcel(list, "派车信息", CollectProductVo.class, response);
    }

    /**
     * 获取派车信息详细信息
     *
     * @param pkId 主键
     */
    @SaCheckLogin
    @GetMapping("/{pkId}")
    public R<CollectProductVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long pkId) {
        return R.ok(iCollectProductService.queryById(pkId));
    }

    /**
     * 新增派车信息
     */
    @SaCheckLogin
    @Log(title = "派车信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CollectProductBo bo) {
        return toAjax(iCollectProductService.insertByBo(bo));
    }

    /**
     * 修改派车信息
     */
    @SaCheckLogin
    @Log(title = "派车信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CollectProductBo bo) {
        return toAjax(iCollectProductService.updateByBo(bo));
    }

    /**
     * 删除派车信息
     *
     * @param pkIds 主键串
     */
    @SaCheckLogin
    @Log(title = "派车信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pkIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] pkIds) {
        return toAjax(iCollectProductService.deleteWithValidByIds(Arrays.asList(pkIds), true));
    }

    /**
     *
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/productList")
    public R productList (@RequestParam Map<String,Object> params,
                          @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                          @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils pageUtils = iCollectProductService.productList(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }


    /**
     * 工地名称下拉列表
     * @param productDept
     * @return
     */
    @GetMapping("/deptList")
    public List<ProductDept> deptList(ProductDept productDept){
        return  iCollectProductService.deptList(productDept);
    }

    @GetMapping("/station")
    public  List<NSysStationDto> station(String id){
        return iCollectProductService.station(id);
    }


    /**
     * 日产能分析统计
     * @param
     * @return
     */
    @GetMapping("/statisticalAnalysisDay/params")
    public List<CollectProductDto> statisticalAnalysisDay(@RequestParam Map<String,Object> params){
        return  iCollectProductService.statisticalAnalysisDay(params);
    }


    /**
     * 产能统计
     * @param type
     * @return
     */
    @GetMapping("/getList")
    public List<CollectProductDto> getList(@RequestParam(required = false) String type,@RequestParam Map<String,Object> params){
        return iCollectProductService.getList(type,params);
    }

    /**
     * 日产能分析列表
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/productListDay")
    public R productListDay (@RequestParam Map<String,Object> params,
                          @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                          @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        return R.ok(iCollectProductService.productListDay(new Query(paramMap).getPage(), params));
    }

    /**
     * 误差分析
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/errorASnalysis")
    public R errorASnalysis (@RequestParam Map<String,Object> params,
                             @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                             @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        return R.ok(iCollectProductService.errorASnalysis(new Query(paramMap).getPage(), params));
    }
}
